<?php
include('../data/comm.inc.php');
include('../data/uservar.php');
include('../func/func.php');
include('../func/csfunc.php');

include('../func/userfunc.php');
include('../include.php');
include('./checklogin.php');

switch ($_REQUEST['xtype']) {
	case "show":
         
$date = $_REQUEST['date'];
if (!preg_match ("/\d{4}-1[0-2]|0?[1-9]-0?[1-9]|[12][0-9]|3[01]/", $date)){
	if(date("His")<str_replace(':','',$config['editstart'])){
       $date = date("Y-m-d",time()-86400);
	}else{
	   $date = date("Y-m-d");
	}
}
		
        $tpage = r1p($_REQUEST['tpage']);
        $psize = $config['psize2'];
       
        $sqls = " and z!=9 and bs=1 and dates='$date' "; 

		$rs= $msql->arr("select count(id) from `$tb_lib` where userid='$userid' $sqls",0);
        $rcount = $rs[0][0];       
		
        $sql = "select qishu,je,peilv1,peilv2,points,content,gid,bid,sid,cid,pid,time,abcd,tid,z from `$tb_lib` where userid='$userid' $sqls order by time desc,id desc limit ";
        $sql .= ($tpage - 1) * $psize . ',' . $psize;
		//echo $sql;
        $msql->query($sql);
        $lib = array();
        $i   = 0;
		$tmp = array();
		$zje=0;
		$rs=0;
        while ($msql->next_record()) {
            $lib[$i]['tid'] = $msql->f('tid');
            $lib[$i]['qishu']  = $msql->f('qishu');
            $lib[$i]['je']     = (float) $msql->f('je');
            $lib[$i]['peilv1'] = (float) ($msql->f('peilv1'));
            $lib[$i]['peilv2'] = (float) ($msql->f('peilv2'));
            $lib[$i]['points']  = (float) $msql->f('points');
            $lib[$i]['content'] = $msql->f('content');
			if($tmp['g'.$msql->f('gid')]==''){
				$tmp['g'.$msql->f('gid')] = transgame($msql->f('gid'),'gname');
			}		
			if($tmp['b'.$msql->f('gid').$msql->f('bid')]==''){
				$tmp['b'.$msql->f('gid').$msql->f('bid')] = transb8('name', $msql->f('bid'),$msql->f('gid'));
			}
			if($tmp['s'.$msql->f('gid').$msql->f('sid')]==''){
				$tmp['s'.$msql->f('gid').$msql->f('sid')] = transs8('name', $msql->f('sid'),$msql->f('gid'));
			}
			if($tmp['c'.$msql->f('gid').$msql->f('cid')]==''){
				$tmp['c'.$msql->f('gid').$msql->f('cid')] = transc8('name', $msql->f('cid'),$msql->f('gid'));
			}
			if($tmp['p'.$msql->f('gid').$msql->f('pid')]==''){
				$tmp['p'.$msql->f('gid').$msql->f('pid')] = transp8('name', $msql->f('pid'),$msql->f('gid'));
			}
			$lib[$i]['gid'] = $tmp['g'.$msql->f('gid')];
			$lib[$i]['wf'] = wf($msql->f('gid'),$tmp['b' . $msql->f('gid') . $msql->f('bid')],$tmp['s' . $msql->f('gid') . $msql->f('sid')],$tmp['c' . $msql->f('gid') . $msql->f('cid')],$tmp['p' . $msql->f('gid') . $msql->f('pid')]);
			$lib[$i]['abcd'] = $msql->f('abcd');
            $lib[$i]['time'] = $msql->f('time');
			$lib[$i]['rs'] = (float)$msql->f('peilv1')*$msql->f('je');
			if($msql->f('z')==1){
			    $lib[$i]['rs'] = (float)($msql->f('peilv1')*$msql->f('je')-$msql->f('je')*(1-$msql->f('points')/100));
			}else if($msql->f('z')==3){
			    $lib[$i]['rs'] = (float)($msql->f('peilv2')*$msql->f('je')-$msql->f('je')*(1-$msql->f('points')/100));
			}else if($msql->f('z')==2){
			    $lib[$i]['rs'] = 0;
			}else{
			    $lib[$i]['rs'] = (float)(0-$msql->f('je')*(1-$msql->f('points')/100));
			}
			$rs += $lib[$i]['rs'];
			$lib[$i]['rs'] = pr2($lib[$i]['rs']);
			$zje += $lib[$i]['je'];
            $i++;
        }
  
		$tpl->assign("lib",$lib);
		$tpl->assign("rs",pr2($rs));
        $tpl->assign("zje",$zje);
		
		$tpl->assign("rcount",$rcount);
		$tpl->assign("psize",$psize);
		$tpl->assign("tpage",$tpage);
		
		$tpl->assign("date",$date);
		$tpl->assign("week",rweek(date('w',strtotime($date))));
       
		 $tpl->display("baoday.html"); 
		 unset($lib);
        unset($out);
        break;

}

?>